<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>两数运算</title>
</head>
<body>
<button onclick="calc()">计算两数运算结果</button>
<script type="text/javascript">
    let num1,num2;//全局变量
    function calc() {
        //局部变量 优先
        let num1 = prompt("请输入第一个数");
        let num2 = prompt("请输入第二个数");
        let opr = prompt("请输入运算符");
        let res ;
        switch (opr) {
            case '+':
                res = parseInt(num1) + parseInt(num2);//字符串
                break;
            case '-': res = num1 - num2; break;
            case '*': res = num1 * num2; break;
            case '/': res = num1 / num2; break;
        }
        alert("两数运算结果为:"+num1+opr+num2+"="+(res));
    }
</script>
</body>
</html>